#include "CommModule.h"
CommModule::CommModule(std::string name)
{
    // 创建eventfd
    m_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
    LOG_INFO("create eventfd=%d\n", m_fd);
    m_commTable=CommTable::get_instance();
    m_commTable->add(name,m_fd);
}

int CommModule::write_message(std::string name,uint64_t value)
{
    int fd=m_commTable->get(name);
    ssize_t result = write(fd, &value, sizeof(value));  // 写入 eventfd
    if (result == -1) {
        printf("write failed: %s\n", strerror(errno));
        LOG_ERROR("write failed: %s", strerror(errno));
    } else {
        // LOG_INFO("write len=%d\n", result);
    }
    return result;
}